unit U_HizmetKartSec;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, StdCtrls, Buttons, ExtCtrls,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxContainer, cxTextEdit,
  cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, wwdblook, siComp;

type
  TfmHizmetKartlariSec = class(TForm)
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1DBTableView1ID: TcxGridDBColumn;
    cxgrid1DBTableView1KARTKODU: TcxGridDBColumn;
    cxgrid1DBTableView1ACIKLAMA: TcxGridDBColumn;
    cxgrid1Level1: TcxGridLevel;
    pnl_alt: TPanel;
    BitBtn1: TBitBtn;
    DSListe: TDataSource;
    adoListe: TADOQuery;
    adoTemp: TADOQuery;
    DSadoAnaHesap: TDataSource;
    DSAnaGider: TDataSource;
    DSAdoAltGider: TDataSource;
    AdoAnaGider: TADOTable;
    AdoAltGider: TADOTable;
    adoAnaHesap: TADOTable;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure cxgrid1DBTableView1DblClick(Sender: TObject);
    procedure cxgrid1DBTableView1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure edAnaHesapCloseUp(Sender: TObject; LookupTable,
      FillTable: TDataSet; modified: Boolean);
    procedure cxgrid1DBTableView1ColumnHeaderClick(
      Sender: TcxGridTableView; AColumn: TcxGridColumn);
  private
    { Private declarations }
  public

  KARTTIPI:integer;
     Kodtext:string;
    ACKtext:string;

      Procedure Listele;
  end;

var
  fmHizmetKartlariSec: TfmHizmetKartlariSec;

implementation

uses ana1;

{$R *.dfm}

procedure TfmHizmetKartlariSec.BitBtn1Click(Sender: TObject);
begin
  close;
end;

procedure TfmHizmetKartlariSec.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 action:=cafree;
 fmHizmetKartlariSec:=nil;
end;

procedure TfmHizmetKartlariSec.FormCreate(Sender: TObject);
begin
  adoAnaHesap.Open;
  AdoAltGider.open;
  AdoAnaGider.open;

  listele;

  Kodtext:='';
  ACKtext:='';
end;

procedure TfmHizmetKartlariSec.cxgrid1DBTableView1DblClick(
  Sender: TObject);
begin
 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('KARTKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('ACIKLAMA').asstring;
 ModalResult:=mrOk;
end;

procedure TfmHizmetKartlariSec.cxgrid1DBTableView1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if key=13 then
begin
 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('KARTKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('ACIKLAMA').asstring;
 ModalResult:=mrOk;
end;

end;

procedure TfmHizmetKartlariSec.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then close;
end;

procedure TfmHizmetKartlariSec.FormShow(Sender: TObject);
begin
if Kodtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_HIZMETKART where AKTIF=1 and KARTKODU like :DD order by KARTKODU';
  adotemp.Parameters.ParamByName('DD').Value:= KodText + '%' ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('KARTKODU', adotemp.fieldbyname('KARTKODU').Value ,[] );

  end;


  if ACKtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_HIZMETKART where AKTIF=1 and ACIKLAMA like :DD order by ACIKLAMA';
  adotemp.Parameters.ParamByName('DD').Value:= AckText + '%'  ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('ACIKLAMA', adotemp.fieldbyname('ACIKLAMA').Value ,[] );

  end;
end;

Procedure TfmHizmetKartlariSec.Listele;
begin
  
  adoListe.close;
  adoListe.SQL.Text:='select * from  CS_HIZMETKART where AKTIF = 1';

  {adoListe.SQL.Add(' and ANAHESAP=:A1');
  adoListe.SQL.Add(' and YARDIMCIHESAP=:A2');
  adoListe.SQL.Add(' and USTHESAP=:A3');
  adoListe.SQL.Add(' and ALTHESAP=:A4');

  adoListe.Parameters.ParamByName('A1').Value := edAnaHesap.LookupValue;
  adoListe.Parameters.ParamByName('A2').Value := 1;
  adoListe.Parameters.ParamByName('A3').Value := edUstHesap.LookupValue;
  adoListe.Parameters.ParamByName('A4').Value := edAltHesap.LookupValue;}

  adoListe.SQL.Add('  order by ACIKLAMA');
  adoListe.Open;
end;

procedure TfmHizmetKartlariSec.edAnaHesapCloseUp(Sender: TObject;
  LookupTable, FillTable: TDataSet; modified: Boolean);
begin
  listele;
end;

procedure TfmHizmetKartlariSec.cxgrid1DBTableView1ColumnHeaderClick(
  Sender: TcxGridTableView; AColumn: TcxGridColumn);
begin
If AColumn.SortOrder = soAscending Then
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' DESC'
  End
  Else
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' ASC';
  End;

  cxgrid1DBTableView1.OptionsBehavior.IncSearchItem := AColumn;
end;

end.